package com.hspedu.map_;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author LiuJinTao
 * @className MapExercise
 * @date 2024/06/10 22:17
 * @description TODO
 */
@SuppressWarnings({"all"})
public class MapExercise {
    public static void main(String[] args) {
        HashMap map = new HashMap();
        map.put(1, new Employee("hsp", 10000, 1));
        map.put(2, new Employee("ljt", 30000, 2));
        map.put(3, new Employee("gjj", 20000, 3));
        Set set = map.keySet();
        for (Object key : set) {
            Employee e = (Employee) map.get(key);
            if (e.getSal() > 18000) {
                System.out.println(e);
            }
        }

        System.out.println("=====第二种遍历方式=====");
        Set entrySet = map.entrySet();
        Iterator iterator1 = entrySet.iterator();
        while (iterator1.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator1.next();
            if (((Employee)entry.getValue()).getSal() > 18000) {
                System.out.println((Employee)entry.getValue());
            }
        }
    }
}

class Employee {
    private String name;
    private double sal;
    private int id;

    public Employee(String name, double sal, int id) {
        this.name = name;
        this.sal = sal;
        this.id = id;
    }

    public Employee() {
    }

    @Override
    public String toString() {
        return "Em{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", id=" + id +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}